package borge.web.teamspirit.trash;

import java.io.Serializable;
import java.util.List;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import borge.web.teamspirit.client.data.Comment;
import borge.web.teamspirit.client.data.Match;
import borge.web.teamspirit.client.interfaces.UserContentProvider;

/**
 * Database object.
 * Representation of a serie.
 * Currently base class for IndepSerie and LeagueSerie.
 * Not sure if this is the best solution??
 * @author Andreas Borglin
 *
 */
@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class Serie implements Serializable {
	
	
	
	/* Encoded key generated by GAE when first saved.
	 * Guaranteed to be unique and contains mapping to 
	 * a team using gae.pk-name key defined below. */
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String iEncodedKey;
    
	// Team we belong to
    @Persistent
    private String iTeamKey;

    @Persistent
	private Integer iPlacement;
	
    @Persistent
	private List<Match> iMatches;
    
    // Non-persistent data for internal use
    
    @NotPersistent
    private List<Comment> iSerieComments;
	
    public Serie(){
        
    }
	
    public static Serie createSerieFromUserForm(Serie aSerie, UserContentProvider aProvider) {

    	/*
        if(aSerie == null)
            aSerie = new Serie();
        
        aSerie.setType(aProvider.getString(TeamSpirit.getConstants().type()));
        aSerie.setStartDate(aProvider.getDate(TeamSpirit.getConstants().start_date()));
        aSerie.setEndDate(aProvider.getDate(TeamSpirit.getConstants().end_date()));
        aSerie.setSeason(aProvider.getString(TeamSpirit.getConstants().season()));
        aSerie.setDivision(aProvider.getString(TeamSpirit.getConstants().division()));
        aSerie.setStatus(aProvider.getString(TeamSpirit.getConstants().status()));
        aSerie.setPlacement(aProvider.getInt(TeamSpirit.getConstants().placement()));
        */
        
        
        return aSerie;
    }
    
    public String toString(){
    	return "";//iSeason + " " + iDivision;
    }
	
/*
	public void setSerieId(Long aSerieId) {
		this.iSerieId = aSerieId;
	}

	public Long getSerieId() {
		return iSerieId;
	}
*/
	
	public void setPlacement(Integer aPlacement) {
		this.iPlacement = aPlacement;
	}

	public Integer getPlacement() {
		return iPlacement;
	}


    
	public void setMatches(List<Match> aMatches) {
		this.iMatches = aMatches;
	}

	public List<Match> getMatches() {
		return iMatches;
	}
	
	public void addMatch(Match aMatch){
		iMatches.add(aMatch);
	}

	public void removeMatch(Match aMatch){
		iMatches.remove(aMatch);
	}
	
	public void removeMatchAt(int aIndex){
		iMatches.remove(aIndex);
	}
	
	/*
	public void setComments(List<Comment> iComments) {
		this.iComments = iComments;
	}

	public List<Comment> getComments() {
		return iComments;
	}
	
	public void addComment(Comment aComment){
		iComments.add(aComment);
	}
	
	
	public void removeComment(Comment aComment){
		iComments.remove(aComment);
	}
	
	public void removeCommentAt(int aIndex){
		iComments.remove(aIndex);
	}*/
    /*
    public String dumpContent(){
        return new String("Dump" +
                "\nId:" + iEncodedKey + 
                "\nType:" + iType.toString() +
                "\nSeason:" + iSeason +
                "\nDivision:" + iDivision +
                "\nStatus:" + iStatus.toString() +
                "\nPlacement:" + iPlacement +
                "\nStart date:" + iStartDate +
                "\nEnd date:" + iEndDate);
    }*/


}
